package com.lz.gmall.search.rpc;

import com.lz.gmall.common.result.Result;
import com.lz.gmall.search.biz.GoodsBizService;
import com.lz.gmall.search.dto.SearchParamDTO;
import com.lz.gmall.search.entity.Goods;
import com.lz.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/inner/search")
public class GoodsRpcController {

    @Autowired
    private GoodsBizService goodsBizService;

    /**
     * 远程调用接口，用于上架商品，把商品信息存入ES数据库中
     * @param goods 商品信息 = 核心检索字段 + 要展示的数据
     * @return
     */
    @PostMapping("/saveGoods")
    public Result saveGoods(@RequestBody Goods goods){
        goodsBizService.saveGoods(goods);
        return Result.ok();
    }

    /**
     * 远程调用接口，用于下架商品，把商品信息从es库中删除
     * @param skuId
     * @return
     */
    @PostMapping("/deleteGoods/{skuId}")
    public Result deleteGoodsById(@PathVariable("skuId")Long skuId){
        goodsBizService.deleteGoodsBySkuId(skuId);
        return Result.ok();
    }

    /**
     * 远程调用接口,根据查询条件进行查询es数据库
     * @param searchParamDTO 封装前端的查询条件
     * @return
     */
    @PostMapping("/searchGoods")
    public Result<SearchResponseVo> search(@RequestBody SearchParamDTO searchParamDTO){
        SearchResponseVo searchResponseVo = goodsBizService.search(searchParamDTO);
        return Result.ok(searchResponseVo);
    }

    /**
     * 远程调用接口,修改热点参数
     * @param hotScore 热点数据
     * @param goodsId 商品id
     * @return
     */
    @GetMapping("/updateHotScore/{goodsId}/{hotScore}")
    public Result updateHotScore(@PathVariable("hotScore")Long hotScore,@PathVariable("goodsId")Long goodsId){
        goodsBizService.updateHotScore(goodsId,hotScore);
        return Result.ok();
    }
}
